<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/const/Error.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/const/Pattern.php';
?>
<SCRIPT type="text/javascript" src="/view/javascripts/form.js"></SCRIPT>
<SCRIPT type="text/javascript" src="/view/javascripts/visibility.js"></SCRIPT>
<?php
$posts = $response->getParameter('posts');
$type = $response->getParameter('types');
if ($type != null){
	$id = $type->getIdentity();
	$name = $type->getName();
	$idPost = $type->getIdPost();
}
	$postName="";
	foreach($posts as $post) {
		if($post->getIdentity()==$idPost){
			$postName=$post->getName();
		}
	}
	$viewId = 'view-'.$id;
	$editId = 'edit-'.$id;
?>
<DIV class="block">
	<H1>
		<A href="/departmenttype/index.html">Типы структурных подразделений</A> ::
<?php
if($id !== null) {
	echo $name;
} else {
?>
		новый тип структурного подразделения
<?php
}
?>
	</H1>
	
	<TABLE>
		<TR>
			<TD>Тип структурного подразделения</TD>
			
			<FORM class="inline" action="/departmenttype/update.html"
						method="post" onsubmit="return checkForm(this)" id="edit-form" name="edit-form">
					<INPUT type="hidden" name="identity" value="<?php echo $id;?>">
					<td>
					<INPUT type="text" name="name" value="<?php echo $name;?>"
							pattern="<?php echo Pattern::WORD;?>"
							message="<?php echo Error::INCORRECT_DEPARTMENT_TYPE_NAME;?>"
							maxlength="30">
					</td>
					</TR>
					<TR>
						<TD>Должность руководителя</TD>
			<TD>
						<SELECT name="idPost" id="idPost">
					<OPTION> </OPTION>
						<?php
								foreach($posts as $post) {
									if($post->getIdentity()==$idPost){
										$postName=$post->getName();
										echo "<OPTION value='$idPost' selected='selected'> $postName</OPTION>";
									}else{
										$postName=$post->getName();
										$idPostCur=$post->getIdentity();
										echo "<OPTION value='$idPostCur'> $postName</OPTION>";
									}
								}
							
						?>
						<OPTION>
							
						</OPTION>
					</SELECT>
					</TR>
					</table>
					
				</FORM>
				<BUTTON type="submit" onclick="submitForm('edit-form')">
						<IMG src="/view/img/button-save.png" alt="">
						<SPAN>сохранить</SPAN>
					</BUTTON>
				<?php if ($type!=null){ ?>
				<FORM class="inline" action="/departmenttype/delete.html" method="post">
					<INPUT type="hidden" name="identity" value="<?php echo $id;?>">
					<BUTTON type="submit">
						<IMG src="/view/img/button-delete.png" alt="">
						<SPAN>удалить</SPAN>
					</BUTTON>
				</FORM>
				<?php } ?>
				
				<BUTTON type="button"
						onclick="location.href='/departmenttype/index.html'">
					<IMG src="/view/img/button-back.png" alt="">
					<SPAN>отмена</SPAN>
				</BUTTON>
			
			